def my_permutations(iterable, r=None):
    if r is None:
        r = len(iterable)
    if r == 0:
        return [()]
    result = []
    for i, item in enumerate(iterable):

        remaining = iterable[:i] + iterable[i + 1:]
        for sub_perm in my_permutations(remaining, r - 1):

            result.append((item,) + sub_perm)
    return result




